home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / tool / fapxtool / src / txl / txlcraft.c < prev    next >
C/C++ Source or Header  |  1995-02-11  |  3KB  |  153 lines

  1. /***************
  2. *
  3. * g:\exe\txl\src\txlcraft.c
  4. */
  5. #include "txl.h"
  6.  
  7. int craftbf(char *basename, FILE *fw)
  8. {
  9.     FILE *fp;
  10.     char *token;
  11.     int ret = 1, i;
  12.     int kind = 0, num = 0;
  13.  
  14.     for (i = 1; i <= 2; i++) {
  15.         switch (basename[strlen(basename) - i]) {
  16.         case '~':
  17.         case '&':
  18.             num = 10;
  19.         case '_':
  20.         case '%':
  21.             kind = 1;    /* MES */
  22.             if (i == 2) {
  23.                 if (basename[strlen(basename) - 1] == 'A') {
  24.                     num += 10;
  25.                 }
  26.                 else if (basename[strlen(basename) - 1] <= '9') {
  27.                     num += basename[strlen(basename) - 1] - '0';
  28.                 }
  29.                 else {
  30.                     num = 0;
  31.                 }
  32.             }
  33.             break;
  34.         case '$':
  35.             num = 10;
  36.         case '#':
  37.             kind = 2;    /* DLL */
  38.             if (i == 2) {
  39.                 if (basename[strlen(basename) - 1] == 'A') {
  40.                     num += 10;
  41.                 }
  42.                 else {
  43.                     num += basename[strlen(basename) - 1] - '0';
  44.                 }
  45.             }
  46.             break;
  47.         }
  48.         if (kind) {
  49.             if (kind == 1) {
  50.                 sprintf(line3, "mes=%d;", num);
  51.             }
  52.             else if (kind == 2) {
  53.                 sprintf(line3, "lib=%d;", num);
  54.             }
  55.             basename[strlen(basename) - i] = NUL;
  56.             break;
  57.         }
  58.     }
  59.  
  60.     if ((fp = fopen(txfsetfile, "rt")) == NULL) {
  61.         return (1);    /* fapxtxf.set は存在しない */
  62.     }
  63.     while (!feof(fp)) {
  64.         fgets(line1, 80, fp);
  65.         if (*line1 != '$') {
  66.             continue;
  67.         }
  68.         if ((token = strchr(line1, '\n')) != NULL) {
  69.             *token = NUL;
  70.         }
  71.         if ((token = strchr(line1, '=')) == NULL) {
  72.             continue;
  73.         }
  74.         if (strncmp(token+1, basename, strlen(basename)) == 0) {
  75.             *token = NUL;
  76.             if (strlen(line1 + 1) > 8) {
  77.                 if (matchstr("***%%%%%HP", line1+1)) {
  78.                     *(line1 + 9) = NUL;
  79.                     sprintf(line2, "hp=%s;", line1+1);
  80.                 }
  81.                 else if (matchstr("***%%%%%PT", line1+1)) {
  82.                     *(line1 + 9) = NUL;
  83.                     sprintf(line2, "patio=%s;", line1+1);
  84.                 }
  85.                 else {
  86.                     continue;
  87.                 }
  88.             }
  89.             else {
  90.                 sprintf(line2, "forum=%s;", line1+1);
  91.             }
  92.             if (num) {
  93.                 strcat(line2, line3);
  94.             }
  95.             fputs(line2, fw);
  96.             ret = 0;
  97.             break;
  98.         }
  99.     }
  100.     fclose(fp);
  101.     return (ret);
  102. }
  103.  
  104. int craftfb(char *forumname, FILE *fw)
  105. {
  106.     FILE *fp;
  107.     char *token;
  108.     int ret = 1;
  109.  
  110.     if ((fp = fopen(txfsetfile, "rt")) == NULL) {
  111.         return (1);    /* fapxtxf.set は存在しない */
  112.     }
  113.     while (!feof(fp)) {
  114.         fgets(line1, 80, fp);
  115.         if (*line1 != '$') {
  116.             continue;
  117.         }
  118.         if ((token = strchr(line1, '\n')) != NULL) {
  119.             *token = NUL;
  120.         }
  121.         if (strncmp(line1+1, forumname, strlen(forumname)) == 0) {
  122.             if ((token = strchr(line1, '=')) == NULL) {
  123.                 break;
  124.             }
  125.             fputs(token + 1, fw);
  126.             ret = 0;
  127.             break;
  128.         }
  129.     }
  130.     fclose(fp);
  131.     return (ret);
  132. }
  133.  
  134. void craftname(char *val[], int (*func)(char *name, FILE *fw))
  135. {
  136.     FILE *fw = NULL;
  137.  
  138.     fprintf(stderr, "TXL: craftname\n");
  139.  
  140.     outputfile = val[1];    /* outputfile        */
  141.     if (*outputfile != NUL) {
  142.         fw = fopen(outputfile, "w");
  143.     }
  144.     if (fw == NULL) {
  145.         Exit(1);
  146.     }
  147.     if ((*func)(val[0], fw)) {
  148.         fputs("not found", fw);
  149.     }
  150.     fclose(fw);
  151.     Exit(0);
  152. }
  153.